package com.company.netease2021;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main1 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String firstLine = br.readLine();
        int m = Integer.parseInt(firstLine.split(" ")[0]);
        int n = Integer.parseInt(firstLine.split(" ")[1]);
        Map<Integer, TreeNode> trees = new HashMap<>();
        TreeNode root = new TreeNode(1);
        trees.put(1, root);
        // 创建
        for (int i = 0; i < n; i++) {
            String relations = br.readLine();
            int parent = Integer.parseInt(relations.split(" ")[0]);
            int child = Integer.parseInt(relations.split(" ")[2]);
            String relation = relations.split(" ")[1];
            if (trees.containsKey(parent)) {
                TreeNode t = trees.get(parent);
                if (relation.equals("left")) {
                    TreeNode sub = new TreeNode(child);
                    trees.put(child,sub);
                    t.left = sub;
                } else {
                    TreeNode sub = new TreeNode(child);
                    trees.put(child,sub);
                    t.right = sub;
                }
            } else {
                TreeNode t = new TreeNode(parent);
                trees.put(parent, t);
                if (relation.equals("left")) {
                    TreeNode sub = new TreeNode(child);
                    trees.put(child,sub);
                    t.left = sub;
                } else {
                    TreeNode sub = new TreeNode(child);
                    trees.put(child,sub);
                    t.right = sub;
                }
            }
        }

        int res = getCherryBeryyies(root);
        System.out.println(res);
        br.close();

    }

    private static int getCherryBeryyies(TreeNode root) {
        int res = 0;
        if (root == null) {
            return res;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        while (!queue.isEmpty()) {
            TreeNode t = queue.poll();
            if(isCherryBerries(t)){
                res++;
            }

            if (t.left != null) {
                queue.offer(t.left);
            }
            if (t.right != null) {
                queue.offer(t.right);
            }


        }
        return res;
    }

    private static boolean isCherryBerries(TreeNode root) {
        return root != null && root.left != null && root.right != null && isLeaf(root.left) && isLeaf(root.right);
    }

    private static boolean isLeaf(TreeNode root) {
        return root.left == null && root.right == null;
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    public TreeNode(int val) {
        this.val = val;
    }

}